package main.Q1801_1900;

import java.util.*;

public class Q1831_1840 {
    public static void main(String[] args) {
        System.out.println("Question1831：");
        System.out.println("Question1832：判断句子是否为全字母句");
        System.out.println("Question1833：雪糕的最大数量");
        System.out.println("Question1834：");
        System.out.println("Question1835：");
        System.out.println("Question1836：");
        System.out.println("Question1837：");
        System.out.println("Question1838：最高频元素的频数");
        System.out.println("Question1839：");
        System.out.println("Question1840：");
    }
}

class Question1832 {
    public boolean checkIfPangram(String sentence) {
        int[] counts = new int[26];
        int count = 0;
        for (char c : sentence.toCharArray()) {
            if (counts[c - 'a'] == 0) {
                count++;
                counts[c - 'a']++;
            }
            if (count==26) break;
        }
        return count == 26;
    }
}

class Question1833 {
    public int maxIceCream(int[] costs, int coins) {
        int result = 0;
        Arrays.sort(costs);
        for (int i = 0; i < costs.length; i++) {
            if (coins >= costs[i]) {
                result++;
                coins -= costs[i];
                continue;
            }
            break;
        }
        return result;
    }
}

class Question1838 {
    public boolean process(int[] nums, int k, int count, int[] sum) {//任意相邻的count个元素满足即为true
//        int length= nums.length;
//        for (int i=0;i<=length-count;i++){
//            int target=nums[i+count-1];//频数元素
//            int temp=k;
//            for (int j=i;j<i+count-1;j++) temp-=target-nums[j];//检验频数元素的前几个元素是否能达到频数元素的值
//            if (temp>=0) return true;//满足情况
//        }
        return false;
    }

    public int maxFrequency(int[] nums, int k) {
//        int left=0,right= nums.length;
//        int[] sum=new int[right+1];
//        for (int i=1;i<=right;i++) sum[i]=sum[i-1]+nums[i-1];
//        Arrays.sort(nums);
//        while (left<right){
//            int mid=left+(right-left)/2;
//            if (process(nums,k,mid,sum)) left=mid;
//            else right=mid-1;
//        }
//        return left;
        int n = nums.length;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i : nums) map.put(i, map.getOrDefault(i, 0) + 1);
        List<Integer> list = new ArrayList<>(map.keySet());
        Collections.sort(list);
        int ans = 1;
        for (int i = 0; i < list.size(); i++) {
            int x = list.get(i), cnt = map.get(x);
            if (i > 0) {
                int p = k;
                for (int j = i - 1; j >= 0; j--) {
                    int y = list.get(j);
                    int diff = x - y;
                    if (p >= diff) {
                        int add = p / diff;
                        int min = Math.min(map.get(y), add);
                        p -= min * diff;
                        cnt += min;
                    } else {
                        break;
                    }
                }
            }
            ans = Math.max(ans, cnt);
        }
        return ans;
    }
}